package com.doit.day04

import scala.io.Source

object _06_线段重叠案例 {
  def main(args: Array[String]): Unit = {

    val list: List[String] = Source.fromFile("data/line.txt").getLines().toList

    //如果说，我现在能得到所有的线段  list(1-2,2-3,3-4,2-3,3-4,4-5.。。。)   怎么转换的问题
    //怎么转换
    val flatten: List[Int] = list.map(line => {
      val arr: Array[String] = line.split(",")
      val start: String = arr(0)
      val end: String = arr(1)
      val range = start.toInt.until(end.toInt)
      range
    }).flatten

    flatten.groupBy(word=>word)
      .map(tp=>(tp._1,tp._2.size))
      .map(tp=>{
        val start: Int = tp._1
        (start+"-"+(start+1),tp._2)
      }).foreach(println)



  }

}
